/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cput.tp.patterns.behaviour.iterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Malotana
 */
public class Menu {
    List<Item> menuItems;
    
    public Menu(){
        menuItems = new ArrayList<Item>();
    }
    
    public void addItem(Item item){
        menuItems.add(item);
    }
    
    class MenuIterator implements Iterator<Item>{
        int currentIndex = 0;
        
        @Override
        public boolean hasNext(){
            if (currentIndex >= menuItems.size() ){
                return false;
            }else
                return true;
           }
        
        @Override
        public Item next(){
            return menuItems.get(currentIndex++);
        }
        
        @Override
        public void remove(){
            menuItems.remove(--currentIndex);
        }
    }
}